import 'package:flutter/material.dart';

class MyRichText extends StatefulWidget {
  MyRichText({
    Key? key,
    required this.child,
    required this.textSpan
  }) : super(key: key);

  TextSpan textSpan;
  Widget child;

  @override
  _MyRichTextState createState() => _MyRichTextState();
}

class _MyRichTextState extends State<MyRichText> {
  @override
  Widget build(BuildContext context) {
    return Center(
      child: Column(
        children: <Widget>[
          Text.rich(widget.textSpan),
          widget.child,
        ],
      ),
    );
  }

  @override
  void didUpdateWidget(MyRichText oldWidget) {
    print('更新');
    if (oldWidget.textSpan != widget.textSpan) {
      widget.textSpan = parText('https://taobao.com');
    } else{
      widget.textSpan = parText('https://baidu.com');
    }
    super.didUpdateWidget(oldWidget);
  }

  TextSpan parText(String text) {
    return TextSpan(
      text: text,
      style: const TextStyle(fontSize: 30, color: Colors.blueAccent),
    );
  }
}
